﻿using LyData.Data;
using System;
using System.Data;
using System.Web;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Admin_Page : System.Web.UI.Page
{
    protected void Bind()
    {
        string str = base.Request.QueryString["menuId"];
        IDb db = new DbFactory().DriverDb();
        db.Open();
        DataRow row = db.TopRow("MenuName,FileName,MenuId", "menu", string.Format("MenuId={0}", str), "");
        DataRow row2 = db.TopRow("PageContent,SinglePageId", "singlePage", string.Format("MenuId={0} AND parentId=0", str), "");
        if (row2 == null)
        {
            string[,] includeColumns = new string[,] { { "Title", (string)row["MenuName"], "NVarChar", "0" }, { "FileName", (string)row["FileName"], "NVarChar", "32" }, { "MenuId", str, "int", "0" }, { "PageContent", "", "NVarChar", "0" }, { "SiteLanguage", SiteInfo.SiteLanguage(), "int", "0" } };
            db.Insert("SinglePage", includeColumns);
        }
        else
        {
            this.FCKeditor1.Text = (string)row2[0];
            this.UpDate.Enabled = true;
            if (!ManagerLogin.ValidateRole(string.Format("0_{0}_c", row2[1].ToString())))
            {
                this.Msg.CssClass = "errorMsg";
                this.Msg.Text = "您无此权限";
                this.Msg.Visible = true;
                this.UpDate.Enabled = false;
            }
        }
        db.Close();
        this.Session["MenuName"] = (string)row["MenuName"];
        this.Session["FileName"] = (string)row["FileName"];
        this.Session["MenuId"] = (string)row["MenuId"];
        this.MenuName.Text = (string)row["MenuName"];
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        this.Msg.Visible = false;
        if (!base.IsPostBack)
        {
            this.Bind();
        }
    }

    protected void UpDate_Click(object sender, EventArgs e)
    {
        string str = (string)this.Session["MenuId"];
        string str2 = (string)this.Session["FileName"];
        string str3 = (string)this.Session["MenuName"];
        if (str == null)
        {
            ManagerLogin.Out();
        }
        string[,] includeColumns = new string[,] { 
            { "Title", str3, "NVarChar", "0" }, 
            { "FileName", str2, "NVarChar", "32" }, 
            { "PageContent", this.FCKeditor1.Text.ToString(), "NText", "0" } 
        };
        IDb db = new DbFactory().DriverDb();
        db.Open();
        db.Update("singlePage", includeColumns, string.Format("MenuId={0} AND ParentId =0", str));
        db.Close();
        this.Msg.Text = "内容更新成功！";
        this.Msg.Visible = true;
    }
}
